import { Body, Controller, Get, Post, UploadedFile, UseInterceptors } from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { UtilsService } from "../service/utils.service";
import { jsonBaseResponse } from "../utils/response/response";
import { convertDocx } from "../utils/docx_template";
import { assets_path } from "../main";

@Controller("/api/utils")
export class UtilsController {
  constructor(
    private readonly utilsService: UtilsService
  ) {
  }

  @Post("uploadFile")
  @UseInterceptors(FileInterceptor("file"))
  async uploadFile(@UploadedFile() file: Express.Multer.File, @Body() body: any) {

    return jsonBaseResponse({
      upload_url: await this.utilsService.uploadFile(file, body.path)
    });
  }

  @Get("test")
  async test() {
    await convertDocx(
      `${assets_path}/temp/浅爸城市合伙人合作协议.docx`,
      `${assets_path}/temp/test.docx`,
      {
        contact: "张三",
        contact_way: "12345678901",
        id_card: "123456789012345678",
        address: "广东省广州市天河区",
        wechat: "12345678901",
        signer:`${assets_path}/temp/signer.png`,
        //年月日
        date: "2021年01月01日"
      }
    );
    return "121212";
  }
}
